﻿using System.Collections.Generic;
using AutoMapper;
using IDI.Studio.Infrastructure.Crosscutting.NetFramework.Adapter;
using IDI.Studio.Infrastructure.Crosscutting.Tests.Classes;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace IDI.Studio.Infrastructure.Crosscutting.Tests
{
    [TestClass()]
    public class UnitTestAutomapperTypeAdapter
    {
        [TestMethod()]
        public void AutoMapperTypeAdapterAdaptEntity()
        {
            //Arrange
            Mapper.Initialize(cfg => cfg.AddProfile(new TypeAdapterProfile()));
            var typeAdapter = new AutomapperTypeAdapter();

            var customer = new Customer()
            {
                Id = 1,
                FirstName = "Jhon",
                LastName = "Bep"
            };

            //act

            var dto = typeAdapter.Adapt<Customer, CustomerDTO>(customer);

            //Assert
            Assert.IsNotNull(dto);
            Assert.AreEqual(dto.CustomerId, customer.Id);
            Assert.AreEqual(dto.FullName, string.Format("{0},{1}", customer.LastName, customer.FirstName));
        }
        [TestMethod()]
        public void AutoMapperTypeAdapterAdaptEntityEnumerable()
        {
            //Arrange
            Mapper.Initialize(cfg => cfg.AddProfile(new TypeAdapterProfile()));
            var typeAdapter = new AutomapperTypeAdapter();

            var customer = new Customer()
            {
                Id = 1,
                FirstName = "Jhon",
                LastName = "Bep"
            };

            //act

            var dto = typeAdapter.Adapt<IEnumerable<Customer>, List<CustomerDTO>>(new Customer[] { customer });

            //Assert
            Assert.IsNotNull(dto);
            Assert.IsTrue(dto.Count == 1);
            Assert.AreEqual(dto[0].CustomerId, customer.Id);
            Assert.AreEqual(dto[0].FullName, string.Format("{0},{1}", customer.LastName, customer.FirstName));
        }
    }
}
